<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="姓名" prop="name">
      <el-input v-model="dataForm.name" placeholder="姓名"></el-input>
    </el-form-item>
    <el-form-item label="专业" prop="major">
      <el-input v-model="dataForm.major" placeholder="专业"></el-input>
    </el-form-item>
    <el-form-item label="指导老师" prop="instructor">
      <el-input v-model="dataForm.instructor" placeholder="指导老师"></el-input>
    </el-form-item>
    <el-form-item label="订单状态">
    </el-form-item>
    <el-select v-model="dataForm.orderState" placeholder="请选择">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
    
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        options: [{
          value: '0',
          label: '初始化'
        }, {
          value: '10',
          label: '未完成'
        }, {
          value: '20',
          label: '已完成'
        }, {
          value: '30',
          label: '已交付'
        }],
        dataForm: {
          id: 0,
          name: '',
          major: '',
          instructor: '',
          categoryId: '',
          categoryPid: '',
          orderState: '',
          createTime: '',
          updateTime: ''
        },
        dataRule: {
          name: [
            { required: true, message: '姓名不能为空', trigger: 'blur' }
          ],
          major: [
            { required: true, message: '专业不能为空', trigger: 'blur' }
          ],
          instructor: [
            { required: true, message: '指导老师不能为空', trigger: 'blur' }
          ],
          categoryId: [
            { required: true, message: '分类id不能为空', trigger: 'blur' }
          ],
          categoryPid: [
            { required: true, message: '分类父id不能为空', trigger: 'blur' }
          ],
          orderState: [
            { required: true, message: '订单状态0初始化;10:未完成;20:已完成;30:已交付不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`//tinformationentry/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.name = data.tInformationEntry.name
                this.dataForm.major = data.tInformationEntry.major
                this.dataForm.instructor = data.tInformationEntry.instructor
                this.dataForm.categoryId = data.tInformationEntry.categoryId
                this.dataForm.categoryPid = data.tInformationEntry.categoryPid
                this.dataForm.orderState = data.tInformationEntry.orderState
                this.dataForm.createTime = data.tInformationEntry.createTime
                this.dataForm.updateTime = data.tInformationEntry.updateTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`//tinformationentry/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'name': this.dataForm.name,
                'major': this.dataForm.major,
                'instructor': this.dataForm.instructor,
                'categoryId': this.dataForm.categoryId,
                'categoryPid': this.dataForm.categoryPid,
                'orderState': this.dataForm.orderState,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
